/*
 *  Texture.c
 *  graphics1
 *
 *  Created by Javier Quevedo on 12/7/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#if defined(WIN32)
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#endif
#import "glutil.h"
#import "Texture.h"
Texture* initTexture (const char *imageFile)
{
	Texture *newTexture = malloc(sizeof(Texture));
	newTexture->textureImage=LoadRGB(imageFile);
	
	glGenTextures(1, &newTexture->textureName);
	glBindTexture(GL_TEXTURE_2D, newTexture->textureName);
	glTexImage2D(GL_TEXTURE_2D, 0, newTexture->textureImage->components, newTexture->textureImage->sizeX, 
				newTexture->textureImage->sizeY, 0, newTexture->textureImage->format, GL_UNSIGNED_BYTE, newTexture->textureImage->data); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); 
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	return newTexture;
}
